function select_temp_logs(the){
	layer.load();
	$.post('/admin/template/logs',{id: $(the).val(), _token: LA.token},function(res){
		layer.closeAll('loading');
		$('textarea[name=content]').html(res.contents);
		window.editor.setValue(res.content);
	},'json')
}
function radio_click(the)
{
	var id = $(the).val()
	select_pattern(id)
}
function select_pattern(id){
	console.log(id);
	if(!id)return ;
	if(id == 1)
	{
		console.log(123);
		$('#embed-hand_setting').prev().prev('.row').show();
		$('#embed-hand_setting').show();
		$('#has-many-fields').show();
		$('#has-many-fields').prev().prev('.row').show();
		$('#embed-auto_setting').prev().prev('.row').hide();
		$('#embed-auto_setting').hide();
	}else{
		console.log(456);
		$('#embed-auto_setting').prev().prev('.row').show();
		$('#embed-auto_setting').show();
		$('#embed-hand_setting').prev().prev('.row').hide();
		$('#embed-hand_setting').hide();
		$('#has-many-fields').hide();
		$('#has-many-fields').prev().prev('.row').hide();
	}
}
function show_right()
{
	$('.control-sidebar.control-sidebar-light').toggleClass('control-sidebar-open')
}
function post_ding(id)
{
	layer.load();
	$.post('/admin/positionlist/ding',{id: id, _token: LA.token},function(res){
		layer.closeAll('loading');
		toastr.success('成功 !');
	},'json')
}
function collects_result(id)
{
	layer.load();
	$.post('/admin/auction/collects_result',{id: id, _token: LA.token},function(res){
		layer.closeAll('loading');
		toastr.success('成功 !');
	},'json')
}
function sum_all(id)
{
	layer.load();
	$.post('/admin/auction/sum_all',{id: id, _token: LA.token},function(res){
		layer.closeAll('loading');
		toastr.success('成功 !');
	},'json')
}
function build_index()
{
	layer.load();
	$.post('/admin/home/build_index',{_token: LA.token},function(res){
		layer.closeAll('loading');
		toastr.success('成功 !');
	},'json')
	
}
function build_common(filed, id)
{
	layer.load();
	$.post('/admin/home/build_common',{_token: LA.token, filed:filed,id:id},function(res){
		layer.closeAll('loading');
		if(res.msg)
		{
			toastr.success(res.msg);
		}else{
			toastr.success('成功 !');
		}
		
	},'json')
	
}
function build_page(id)
{
	layer.load();
	$.post('/admin/page/build_page',{_token: LA.token,id:id},function(res){
		layer.closeAll('loading');
		toastr.success('成功 !');
	},'json')
}
function htmlspecialchars(str){            
    str = str.replace(/&/g, '&amp;');  
    str = str.replace(/</g, '&lt;');  
    str = str.replace(/>/g, '&gt;');  
    str = str.replace(/"/g, '&quot;');  
    str = str.replace(/'/g, '&#039;');  
    return str;  
}
function select_skin(the)
{
	layer.load();
	$.post('/admin/home/skin',{skin:$(the).val(),_token: LA.token},function(res){
		layer.closeAll('loading');
		location.reload();
	},'json')
}
function deletefile(the, id)
{
	layer.load();
	$.post('/admin/delete_atlas_item',{id: id, _token: LA.token},function(res){
		layer.closeAll('loading');
		toastr.success('成功 !');
		$(the).parent().parent().remove();
	},'json')
	
}

function domain_repleate()
{
	var value = $('#domain_repleate').val();
	var artists_id = $('#artists_id').val();
	$.post('/admin/domain_repleate',{value: value,artists_id:artists_id, _token: LA.token},function(res){
		layer.closeAll('loading');
		if(res.status == 1)
		{
			layer.msg('域名已重复 !');
		}else{
			layer.msg('域名可以使用 !');
		}
		
	},'json')
}
function GetQueryString(name) {

   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");

   var r = window.location.search.substr(1).match(reg);

   if (r!=null) return (r[2]); return null;

}
function GetQueryStringUrl(url,name) {

   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");

   var r = url.substr(1).match(reg);

   if (r!=null) return (r[2]); return null;

}
$(document).on('pjax:complete', function() {
	if($('select[name=pattern]').val())
	{
		select_pattern($('select[name=pattern]').val());
	}
	$('#domain_repleate').blur(function(){
		domain_repleate();
	})
	var artists_id = GetQueryString('artists_id');
	var auctions_id = GetQueryString('auctions_id');
	var zc_id = GetQueryString('zc_id');

	if(artists_id)
	{
		var url = $('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href')
		if(url && !GetQueryStringUrl(url, 'artists_id'))
		{
			if(url.indexOf('?') < 0)
			{
				$('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href', url +'?artists_id='+artists_id);
			}else{
				$('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href', url +'&artists_id='+artists_id);
			}
		}
		
	}

	if(zc_id > 0)
	{
		var url = $('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href')
		
		if(url && !GetQueryStringUrl(url, 'zc_id'))
		{
			if(url.indexOf('?') < 0)
			{
				$('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href', url +'?' + '&zc_id='+zc_id);
			}else{
				$('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href', url + '&zc_id='+zc_id);
			}
			
		}
		
	}
	if(auctions_id > 0)
	{
		var url = $('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href')
		
		if(url && !GetQueryStringUrl(url, 'auctions_id'))
		{
			if(url.indexOf('?') < 0)
			{
				$('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href', url +'?' + '&auctions_id='+auctions_id);
			}else{
				$('.btn-group.pull-right .btn.btn-sm.btn-success').attr('href', url + '&auctions_id='+auctions_id);
			}
			
		}
		
	}
	
	
	
	
	
});